In-Memory Vault Provider

NuGet Package : Nodsoft.MoltenObsidian.Vaults.InMemory

Description

This provider supports creating and managing an Obsidian vault entirely in memory. Unlike other providers that read from external sources, the In-Memory vault is writable and stores all data in memory, making it ideal for testing, temporary vaults, or runtime-generated content.

The In-Memory vault implements IWritableVault, allowing you to create, modify, and delete folders, files, and notes programmatically.

Example Usage

Declare an In-Memory vault in Dependency Injection:

using Microsoft.Extensions.DependencyInjection; 

public void ConfigureServices(IServiceCollection services) 
{ 
	// Declare an In-Memory vault with a name:
	services.AddMoltenObsidianInMemoryVault("MyVault");
}

Alternatively you can instantiate your own In-Memory vault like so:

using Nodsoft.MoltenObsidian.Vaults.InMemory;

// Create a new in-memory vault
IVault vault = new InMemoryVault("MyVault");

// Populate the vault with content
await vault.WriteNoteAsync("Notes/Welcome.md", 
	new MemoryStream(Encoding.UTF8.GetBytes("# Welcome\nThis is a note in memory.")));

await vault.WriteFileAsync("Assets/image.png", imageStream);

Setup Mode

The In-Memory vault supports a "setup mode" which can be enabled to prevent vault update events from being raised during bulk operations:

// Create vault in setup mode
var vault = new InMemoryVault("MyVault", setup: true);

// Populate the vault without triggering events
await vault.WriteNoteAsync("Note1.md", contentStream1);
await vault.WriteNoteAsync("Note2.md", contentStream2);

// Disable setup mode to start receiving events
vault.Setup = false;

Known Limitations (Potential future features?)

If any of those features are considered a necessity in your use case, feel free to voice your need by raising an issue.